import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import AppNavigator from './src/navigation/AppNavigator';
import { useAppState } from './src/hooks/useAppState';
import notificationService from './src/services/notificationService';
import usePlanStore from './src/store/planStore';
import { useTheme } from './src/hooks/useTheme';

export default function App() {
  const { loadAllData } = usePlanStore();
  const { settings } = usePlanStore();
  const { themeMode } = useTheme();
  
  // 初始化应用
  useEffect(() => {
    // 初始化通知服务
    notificationService.initialize();
    
    // 加载数据
    loadAllData();
  }, []);

  // 监听设置变化，更新通知
  useEffect(() => {
    if (settings.enableNotifications && settings.notificationTime) {
      notificationService.scheduleDailyReminder(
        settings.notificationTime,
        '记得制定今天的计划哦！'
      );
    } else {
      notificationService.cancelAllNotifications();
    }
  }, [settings.enableNotifications, settings.notificationTime]);

  useAppState();

  return (
    <SafeAreaProvider>
      <AppNavigator />
      <StatusBar style={themeMode === 'dark' ? 'light' : 'dark'} />
    </SafeAreaProvider>
  );
}

